﻿using System;
using Framework.FSMLite;

namespace Framework.FSMLite
{
    public abstract class StateMachine<TState> where TState : Enum
    {

        public TState State { get; private set; }

        protected StateMachineRunner<TState> stateMachineRunner;
        public    T                          GetStateRunner<T>() where T : StateMachineRunner<TState> { return (T) this.stateMachineRunner; }

        internal void InitNode(StateMachineRunner<TState> stateMachineRunner, TState state)
        {
            this.stateMachineRunner = stateMachineRunner;
            this.State              = state;
            this.OnInit();
        }

        /// <summary>
        /// 状态节点被初始化
        /// </summary>
        protected virtual void OnInit() { }

        /// <summary>
        /// 进入当前状态
        /// </summary>
        protected abstract void OnEnter(params object[] args);

        /// <summary>
        /// 离开当前状态
        /// </summary>
        protected abstract void OnExit();

        internal void _OnEnter(params object[] args) { this.OnEnter(args); }
        internal void _OnExit()                      { this.OnExit(); }

    }
}